package com.alvinlkk.basic.chapter21;

import java.util.concurrent.TimeUnit;

public class SimpleDaemons implements Runnable {

    @Override
    public void run() {
        while(true) {
            try {
                TimeUnit.MILLISECONDS.sleep(100);
                System.out.println(Thread.currentThread() + " " + this );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread daemon = new Thread(new SimpleDaemons());
            //所有非后台线程结束，后台线程也会耕者结束
            daemon.setDaemon(true);
            daemon.start();
        }
        System.out.println("All daemons start ----");
        TimeUnit.MILLISECONDS.sleep(200);
    }

}
